<?php
/**
 * @author      :   hungnt1@fpt.net
 * @name        :   JobMessage
 * @version     :   300312
 * @copyright   :   My company 
 */
class JobMessage
{       
    /**
     * Send mail function
     * @param <array> $params
     * @return <array>
     * @author HungNT1
     */
    public static function sendToEmail($params)
    {
        // Default return
        $response = Fpt_Server::setOutputData(0, '', '');
        
        try {
            // Include config send mail
            include(APPLICATION_PATH.'/configs/mail.php');

            if (is_array($configsender) && !empty ($configsender) )
            {
                // Create transport
                $transport = new Zend_Mail_Transport_Smtp(isset($smtpServer['message']) ? $smtpServer['message']:$smtpServer['default'], $configmail);

                foreach ($params['reciever'] as $email)
                {
                    //init zend mail
                    $mail = new Zend_Mail('UTF-8');

                    //set from
                    $mail->setFrom($configsender['message']['email'],$configsender['message']['name']);

                    //receivers
                    $mail->addTo($email, '');

                    //set content mail
                    $mail->setSubject($params['subject']);
                    
                    $mail->setBodyHtml($params['body']);

                    //send mail
                    if(!$mail->send($transport))
                    {
                        $response['error'] = 1;
                        $response['message'] .= 'Mail err: can not send to: '.$reciever_mail;
                    }
                }                
            }
            else {
                $response['error'] = 1;
                $response['message'] .= 'Empty Sender';
            }
            
        }
        catch (Exception $ex)
        {
            // Log error
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
        }
        
        return $response;
    }
}